package com.llkj.contractmanagement.contractmanagement.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.utils.ImageLoaderUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * author: dong.yj
 * created on: 2016/8/20 16:22
 * description:艺人介绍界面图片数据详情
 */
public class ActorPhotoAdapter extends RecyclerView.Adapter<ActorPhotoAdapter.ViewHolder> {


    /**
     * ItemClick的回调接口
     *
     * @author zhy
     */
    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    private LayoutInflater mInflater;
    private ArrayList<String> mDatas;

    public ActorPhotoAdapter(Context context, ArrayList<String> datats) {
        mInflater = LayoutInflater.from(context);
        mDatas = datats;
    }

    @Override
    public ActorPhotoAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.lv_actorphoto_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.mImg = (ImageView) view.findViewById(R.id.id_index_gallery_item_image);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {

//        holder.mImg.setImageResource(mDatas.get(position));
        ImageLoaderUtil.displayImage(mDatas.get(position), holder.mImg);
        //如果设置了回调，则设置点击事件
        if (mOnItemClickLitener != null) {
            holder.mImg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickLitener.onItemClick(holder.mImg, position);
                }
            });

        }
    }


    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View arg0) {
            super(arg0);
        }

        ImageView mImg;
    }
}
